package app

import (
	"chatgpt/helper/code"
	"chatgpt/logq"
	"chatgpt/plugin/rpcx"
	"chatgpt/services/datasrv/sqlhelper"
	"context"
)

func (self *OrderApi) OrderSelect(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("OrderApi")
	err := client.Call(ctx, "OrderSelect", req, res)
	if err != nil {
		logq.Error("DataSrv.Order.Select err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *OrderApi) OrderSave(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("OrderApi")
	err := client.Call(ctx, "OrderSave", req, res)
	if err != nil {
		logq.Error("DataSrv.Order.Save err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *OrderApi) OrderTotal(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("OrderApi")
	err := client.Call(ctx, "OrderTotal", req, res)
	if err != nil {
		logq.Error("DataSrv.Order.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *OrderApi) OrderFirst(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("OrderApi")
	err := client.Call(ctx, "OrderFirst", req, res)
	if err != nil {
		logq.Error("DataSrv.Order.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *OrderApi) OrderDelete(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("OrderApi")
	err := client.Call(ctx, "OrderDelete", req, res)
	if err != nil {
		logq.Error("DataSrv.Order.Delete err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}
